package com.margo.project.zookeeper.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * 多数据源配置
 * 
 * 配置spring.datasource.slave.url 会报错 jdbcUrl is required with driverClassName
 * 改为 spring.datasource.slave.jdbc-url
 * 参考 https://www.cnblogs.com/jpfss/p/11083472.html
 * @author fangxingbang
 *
 */
@Configuration
public class MargoDataSourceConfiguration {
	
	@Bean
	@ConfigurationProperties("spring.datasource.master")
	public DataSource masterDataSource() {
		return DataSourceBuilder.create().build();
	}
	
	@Bean
	public JdbcTemplate slaveJdbcTmplate(@Qualifier("masterDataSource")DataSource masterDataSource) {
		return new JdbcTemplate(masterDataSource);
	}
}
